package com.sxt.util;

import com.alibaba.fastjson.JSON;
import com.sxt.common.Result;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

public class RespUtil {
    /**
     * 业务结果信息 转化为JSON返回
     * @param response
     * @param rs
     */
    public static void write(HttpServletResponse response, Result rs){
        response.setContentType("text/json;charset=utf-8");
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            String data = JSON.toJSONString(rs);
            writer.print(data);
            writer.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            writer.close();
        }
    }
}
